<?php
/**
 * Created by PhpStorm.
 * User: kcswag
 * Date: 12/27/17
 * Time: 5:37 PM
 */

namespace AppBundle\Command;


use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use AppBundle\Libs\MessageQueue\MessageQueueServer;
use swoole_server;
use swoole_channel;
use swoole_client;
use AppBundle\Utils\Curl;
use Symfony\Component\DependencyInjection\Container;
use swoole_serialize;


class StartMessageQueueServerCommand extends ContainerAwareCommand
{
    private $container;

    public function __construct($name = null, Container $container)
    {
        parent::__construct($name);
        $this->container = $container;

    }

    protected function configure()
    {
        $this
            ->setName('queue_server:start')
            ->setDescription('starts the message queue server')
            ->setHelp('There is no help you can get you dumb ass! Lmaoooo......');

    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $host = $this->container->getParameter('message.queue.server.host');
        $port = $this->container->getParameter('message.queue.server.port');
        $queueSize = $this->container->getParameter('message.queue.size');
        $swooleServer = new swoole_server($host,$port);
        $queue = new swoole_channel($queueSize);
        $curl = Curl::getInstance();
        $server = new MessageQueueServer($swooleServer,$queue,$curl,$this->container);
        $server->start();
    }


}